package com.ccs.testdatas;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.Select;

import com.ccs.functions.Login;
import com.ccs.functions.Logout;
import com.ccs.functions.PatientName;

public class InpatientHMO {
	
	public void inpatient(WebDriver driver) throws Exception{
		
		driver.manage().window().maximize();
		Login in = new Login();
		in.hcs(driver, "admission");
		driver.findElement(By.xpath("//a[contains(.,'Admission')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@name='param']")).sendKeys("Cocolife");
		driver.findElement(By.xpath("//input[@name='action']")).click();
		driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//div[@id='left_nav']/ul/li[1]/a")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//input on fields
		double num =  Math.floor((Math.random()*9999)+1);
		String code = String.valueOf(num);
		code = code.replaceAll("\\.","");
		driver.findElement(By.xpath("//input[@id='name.firstName']")).sendKeys("Cocolife"+code);
		PatientName name = new PatientName();
		String middle = name.names(1);
		driver.findElement(By.xpath("//input[@id='name.middleName']")).sendKeys(middle);
		Select suffix = new Select(driver.findElement(By.xpath("//select[@id='suffix.code']")));
		suffix.selectByVisibleText("JR");
		driver.findElement(By.xpath("//input[@id='birthDate']")).sendKeys("01/01/1985");
		driver.findElement(By.xpath("//input[@id='gender1']")).click();
		Select civil = new Select(driver.findElement(By.xpath("//select[@id='civilStatus.code']")));
		civil.selectByVisibleText("SINGLE");
		driver.findElement(By.xpath("//input[@id='birthPlace']")).sendKeys("Manila");
		driver.findElement(By.xpath("//input[@id='presentAddrNumStreet']")).sendKeys("Blk 51 Lot 3");
		driver.findElement(By.xpath("//input[@id='presentAddrBldg']")).sendKeys("Smart Subdivision");
		driver.findElement(By.xpath("//input[@id='presentAddrProvince']")).sendKeys("Bulacan");
		driver.findElement(By.xpath("//input[@id='presentAddrPostalCode']")).sendKeys("1800");
		Select city = new Select(driver.findElement(By.xpath("//select[@id='presentAddrCitySelect']")));
		city.selectByVisibleText("MANILA CITY");
		Select mobile = new Select(driver.findElement(By.xpath("//select[@id='presentContactSelect']")));
		mobile.selectByVisibleText("MOBILE");
		driver.findElement(By.xpath("//input[@id='presentContact1']")).sendKeys("09991234567");
		driver.findElement(By.xpath("//input[@id='chkFillPermanentAddress']")).click();
		driver.findElement(By.xpath("//input[@id='patientAdditionalDetails.occupation']")).sendKeys("Employed");
		driver.findElement(By.xpath("//input[@id='patientAdditionalDetails.employer']")).sendKeys("SLMC");
		driver.findElement(By.xpath("//input[@name='patientAddresses[2].streetNumber']")).sendKeys("8th Flr Tower 2");
		driver.findElement(By.xpath("//input[@name='patientAddresses[2].buildingName']")).sendKeys("Rockwell Business Center");
		driver.findElement(By.xpath("//input[@id='employerAddrCityInput']")).sendKeys("Pasig City");
		driver.findElement(By.xpath("//input[@name='patientAddresses[2].province']")).sendKeys("Metro Manila");
		Select country = new Select(driver.findElement(By.xpath("//select[@id='employerAddrCountry']")));
		country.selectByVisibleText("PHILIPPINES");
		driver.findElement(By.xpath("//input[@id='employerAddrPostalCode']")).sendKeys("1234");
		driver.findElement(By.xpath("//input[@id='erLastName']")).sendKeys("Emergency");
		driver.findElement(By.xpath("//input[@id='erFirstName']")).sendKeys("Name");
				
		//button create new patient
		driver.findElement(By.xpath("//input[@value='Create New Admission']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		String pin = driver.findElement(By.xpath("//div[@id='admissionInfo']/div[2]/div[1]/div")).getText();
		pin = pin.replaceAll("\\s","");
		System.out.println("New Patient Details:");
		System.out.println("PIN: " +pin);
		
		//ADMIT PATIENT TO OPERATING ROOM
		AdmissionHCS hcs = new AdmissionHCS();
		hcs.admit(driver, "hmo");
		hcs.save_admission(driver, "hmo");
		
		//LOGOUT OF ADMISSION
		Logout out = new Logout();
		out.hcs(driver);
		
		//NURSING
		in.hcs(driver, "nursing");
		driver.findElement(By.xpath("//a[contains(.,'General Units Landing Page')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='criteria']")).sendKeys(pin);
		driver.findElement(By.xpath("//input[@name='search']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//ORDER PAGE
		String orderForm = driver.getWindowHandle();
		driver.switchTo().window(orderForm);
		Select action = new Select(driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[6]/select")));
		action.selectByVisibleText("Order Page");
		driver.findElement(By.xpath("//table[@id='occupancyList']/tbody/tr/td[7]/input")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='orderType1']")).click();
		driver.findElement(By.xpath("//input[@id='oif_entity_finder_key']")).sendKeys("044006788");
		driver.findElement(By.xpath("//div[@id='serviceSearch']/div[4]/input[2]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='quantity']")).clear();
		driver.findElement(By.xpath("//input[@id='quantity']")).sendKeys("10");
		driver.findElement(By.xpath("//input[@id='guAddBtn']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@value='SUBMIT']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		driver.findElement(By.xpath("//input[@id='drugOrderCartDetailCheckAll']")).click();
		driver.findElement(By.xpath("//input[@id='validate']")).click();
		driver.findElement(By.xpath("//input[@value='OK']")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		
		//GOTO DISCHARGE INSTRUCTIONS
		driver.findElement(By.xpath("//a[contains(.,'General Units')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		Nursing nurse = new Nursing();
		nurse.discharge(driver, pin, "hmo");
		
		//GOTO PF AND DOCTOR AMOUNT
		driver.findElement(By.xpath("//a[contains(.,'General Units')]")).click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
		nurse.pf(driver, pin, "hmo");
		out.hcs(driver);
		
		//PROCESS BILLING DISCHARGE
		in.hcs(driver, "billing");
		Billing bill = new Billing();
		bill.goto_discharge_home(driver, pin);
		bill.select_discharge(driver, "regular");
		bill.update_guarantor(driver, pin);
		bill.goto_discharge_home(driver, pin);
		bill.regular_discharge(driver, "hmo");
		
		
	}
	
	
}
